package com.newgrand.utils.i8util;

import com.newgrand.model.QueryResModel;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhaoFengjie
 * @version 1.0
 * @date 2022/7/6 16:45
 */

public class QueryResultUtil {

    public static QueryResModel success() {
        return success("调用成功");
    }

    public static QueryResModel success(String message) {
        return success(message, new ArrayList<>());
    }

    public static <T> QueryResModel success(String message, List<T> data) {
        return success(1, 20, 0, 1, message, data);
    }

    public static <T> QueryResModel success(Integer page, Integer pageSize, Integer total, Integer pages, String message, List<T> data) {
        QueryResModel res = new QueryResModel();
        res.setSuccess(true);
        res.setStatus(200);
        res.setMessage(message);
        res.setData(data);
        res.setPage(page);
        res.setPageSize(pageSize);
        res.setTotal(total);
        res.setPages(pages);
        return res;
    }

    public static QueryResModel error() {
        return error("调用失败");
    }

    public static QueryResModel error(String message) {
        return error(message, new ArrayList<>());
    }

    public static <T> QueryResModel error(String message, List<T> data) {
        QueryResModel res = new QueryResModel();
        res.setSuccess(true);
        res.setStatus(500);
        res.setMessage(message);
        res.setData(data);
        return res;
    }
}
